﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using NetBay.Core.BusinessEntities;
using Rio.Framework.Localisation;
using Rio.Framework.Pages.Context;

namespace Rio.Framework.Pages.ChildWindows
{
    public partial class CreateReportWindow : ChildWindow
    {
        private ObservableCollection<Index> IndexList {get; set;}
        private String FolderIdList { get; set; }
        private long m_lOrganisationId, m_lFolderTypeId;
       
        public CreateReportWindow(long p_lOrganisationId, long p_lFolderTypeId , List<Index> p_lIndex, String p_FolderIds)
        {
            InitializeComponent();
            InitLabel(); 
            IndexList = new ObservableCollection<Index>(p_lIndex);
            IndexListBox.ItemsSource = IndexList;
            IndexListBox.DisplayMemberPath = "IndexLabel";
            FolderIdList = p_FolderIds;
            m_lOrganisationId = p_lOrganisationId;
            m_lFolderTypeId = p_lFolderTypeId;

            TitleBox.ItemsSource = IndexList;
            TitleBox.DisplayMemberPath = "IndexLabel";            
        }

        private void InitLabel()
        {
            this.Title = Resx.GetLabel(ResxFolder.NB_DOC);
            this.OKButton.Content = Resx.GetLabel(ResxCommon.OK);
            this.CancelButton.Content = Resx.GetLabel(ResxCommon.CANCEL);
            this.PageTitle.Text = Resx.GetLabel(ResxFolder.REPORT_PAGE_TITLE);
        }
        
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            Dictionary<long, string> l_oIndexList = new Dictionary<long, string>();
            foreach (Index l_oIndex in IndexListBox.SelectedItems)
            {
                l_oIndexList.Add(l_oIndex.Indentifier, l_oIndex.IndexLabel);
            }

            GlobalWebContext.BusinessEntitiesDomainContext.GeneratePDFReport(m_lOrganisationId, FolderIdList, m_lFolderTypeId, l_oIndexList, ((Index)TitleBox.SelectedItem).Indentifier);
            
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

